﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace FileListMaker
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();

            cmbCondition.LoadConfiguration("cmbCondition");
            cmbPath.LoadConfiguration("cmbPath");
        }

        private void btnStart_Click(object sender, EventArgs e)
        {
            var path = cmbPath.Text.Trim();

            if (path.Length == 0)
            {
                MessageBox.Show("Path is required.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            
            var condition = cmbCondition.Text.Trim();
            if (condition.Length == 0)
                condition = "*.*";

            cmbPath.InsertHistory(path);
            cmbCondition.InsertHistory(condition);

            var resultForm = new ResultForm();
            resultForm.ShowFileListResult(path, new WildCardCondition(condition));
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (MessageBox.Show("Exit?", "Confirm", MessageBoxButtons.YesNo,
                MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == System.Windows.Forms.DialogResult.No)
            {
                e.Cancel = true;
            }
            else
            {
                ControlConfiguration.Current.Save();
            }
        }

        private void btnSelectPathDir_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog dialog = new FolderBrowserDialog();
            dialog.SelectedPath = cmbPath.Text;
            dialog.ShowNewFolderButton = false;
            if (dialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                return;
            cmbPath.Text = dialog.SelectedPath;
        }
    }
}
